{extend name="base/base" /}
{block name="style"}
<style type="text/css">

</style>
{/block}
{block name="content"}
  <div class="layui-form-item layui-form-pane">
    <div class="layui-inline">
        <div class="demoTable">
          <button class="layui-btn layui-btn-normal" onclick="add()">新增</button>
        </div>
      </div>
  <table id="table" lay-filter="table"></table>
    <script type="text/html" id="edit">
    <a class="layui-btn layui-btn-xs" lay-event="edit">权限管理</a>
    <a class="layui-btn layui-btn-xs" lay-event="edit2">编辑</a>
    <a class="layui-btn layui-btn-xs" lay-event="delete">删除</a>
  </script>
</div>
{/block}
{block name="script"}
<script>
layui.use(['table', 'laydate'], function(){
  var table = layui.table;
  var laydate = layui.laydate;
  table.render({
    elem: '#table'
    ,height: 'full-200'
    ,url: '/admin/authority/dataList/' //数据接口
    ,limit:20
    ,page: true //开启分页
    ,id:'table'
    ,cols: [[ //表头
      {field:'name', title: '管理员账号', width: 150}
      ,{field:'remark', title: '权限', width: 200}
      ,{field:'kf1', title: 'whatsapp', width: 200}
      ,{field:'kf2', title: 'telegram', width: 200}
      ,{field:'kf3', title: '群组地址', width: 200}
      // ,{field:'password', title: '密码', width: 150,templet: function(d){
      //   return '';
      // }}
      ,{field:'data_uid', title: '展示数据UID', width: 200}
       ,{field:'level', title: '等级', width: 100,templet: function(d){
        if (d.level == 1) {
          return '<span">总后台</span>'
        }
        if (d.level == 2) {
          return '<span">业务经理</span>'
        }
        if (d.level == 3) {
          return '<span">业务组长</span>'
        }
        if (d.level == 4) {
          return '<span">业务员</span>'
        }
      }}
      ,{title: '操作', toolbar: '#edit', width: 200}
    ]]
  }); 
    //编辑 删除
  table.on('tool(table)', function(obj){
    var data = obj.data;
    if(obj.event === 'edit'){
      layer.open({
        type: 2 ,
        title: '权限管理',   //标题
        area: ['1300px', '700px'],   //宽高
        shade: 0.4,   //遮罩透明度
        content: '/admin/authority/edit?uid='+data.id,//支持获取DOM元素
        });
    }
    if(obj.event === 'delete'){
      layer.confirm('确认删除？', {
        btn: ['确定','取消'] //按钮
      }, function(){
        $.ajax({
            url:"{:url('admin/admin/delete')}",
            type:"POST",
            data:{id:data.id},
            success:function(ret){
                if (ret.code == 0) {
                  layer.msg('操作成功');
                  $(".layui-laypage-btn")[0].click();
                  //window.location.reload();
                }
                if (ret.code == 1) {
                    layer.msg(ret.msg);
                }
            }
        });
      }, function(){ 
      });
    }
    if(obj.event === 'edit2'){
      layer.open({
        type: 2 ,
        title: '编辑管理员',   //标题
        area: ['1300px', '700px'],   //宽高
        shade: 0.4,   //遮罩透明度
        content: '/admin/admin/add?id='+data.id,//支持获取DOM元素
        });
    }
  });
});

function add(){
  layer.open({
        type: 2 ,
        title: '新增管理员',   //标题
        area: ['800px', '600px'],   //宽高
        shade: 0.4,   //遮罩透明度
        content: '/admin/admin/add',//支持获取DOM元素
        end: function(){
          window.location.reload();
        }
        });
}
</script>
{/block}


